package cp4.test;

import util.CookieReader;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/cp4/req/loginSuccess")
public class LoginSuccessServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        CookieReader cookieReader = new CookieReader(req);
        // 登录的servlet将所有的请求转发过来 所以能够达到请求的参数
        String name = cookieReader.get("user_name");

        out.println("<h1>登录成功</h1>");
        out.println("<br>欢迎您:" + name);
        out.println("<a href=\"/result.jsp\">打开结果也</a>");
        out.println(req.getAttribute("myName"));
    }
}
